package com.asiainfo.complier.editor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import com.asiainfo.complier.editor.JavaKeyWord.Types;

public class JavaKeyWordManager {
	private static ArrayList<JavaKeyWord> list = new ArrayList<JavaKeyWord>();

	public JavaKeyWordManager() {
		loadKeyWord();
	}

	public void loadKeyWord() {

	}

	static {
		InputStream fs = ClassLoader
				.getSystemResourceAsStream("com/asiainfo/complier/conf/Java.cfg");
		BufferedReader reader = new BufferedReader(new InputStreamReader(fs));
		String line = null;
		try {
			while ((line = reader.readLine()) != null) {

				if (!line.startsWith("#")) {
					JavaKeyWord keyWord = new JavaKeyWord();
					keyWord.setName(line.trim());
					keyWord.setType(Types.CLASS);
					list.add(keyWord);
				}
			}
		} catch (IOException e) {

			e.printStackTrace();
		}

	}

	/**
	 * show Auto Complete
	 * 
	 * @param curkeyWord
	 * @param ui
	 * @return
	 */
	public boolean showAutoComplete(String curkeyWord, AutoCompleteUI ui) {

		boolean hasKeyWord = false;
	 
		ArrayList<JavaKeyWord> curList = new ArrayList<JavaKeyWord>();
		for (JavaKeyWord word : list) {
			if (word.getName().toLowerCase()
					.startsWith(curkeyWord.toLowerCase())) {
				curList.add(word);
				hasKeyWord = true;
			}
		}
		ui.setShowData(curList);
		return hasKeyWord;

	}
}
